草庐IT

C++ operator+ 和 operator+= 重载

全部标签

c++ - 从模板检查成员函数重载是否存在

是否可以从模板成员函数中检查一个类是否有某个成员函数重载?我能找到的最好的类似问题是这个:Isitpossibletowriteatemplatetocheckforafunction'sexistence?据我了解,这不适用于检查函数重载的情况。这是一个如何应用它的简化示例:structA;structB;classC{public:templatevoiddoSomething(std::stringasdf){Tdata_structure;/**somecode*/if(OVERLOAD_EXISTS(manipulateStruct,T)){manipulateStruct(

c++ - 试图在 C++ 中重载增量运算符

这个问题在这里已经有了答案:Whatarethebasicrulesandidiomsforoperatoroverloading?(8个答案)关闭4年前。到目前为止,除了这个以外,每个运算符(operator)都工作正常。当我运行代码时,出现错误:“错误:后缀‘ComplexComplex::operator++(Complex)’必须以‘int’作为参数|”这是我的代码:#include#includeusingnamespacestd;classComplex{friendistream&operator>>(istream&,Complex&);friendostream&op

c++ - 将 Boost 参数与 operator() 一起使用

我想将BoostParameter与重载调用运算符(operator())一起使用:#include#include#includestructadd_argument_tag{structname_;structdescr_;};staticinlineboost::parameter::keyword&name=boost::parameter::keyword::get();staticinlineboost::parameter::keyword&descr=boost::parameter::keyword::get();structconfig{BOOST_PARAMETE

c++ - 使用 ref-qualifiers 重载解析模板方法

我正在使用特殊类型开发一个具有编译时访问功能的容器。我还希望有一个使用数字的访问函数,以便为所有元素实现操作。因此我有这样的东西:structS{templateint&f();templateint&f();};我想禁止访问临时对象,所以我为类型访问添加了一个重载:structS{templateint&f();templateint&f()&;templateint&f()&&=delete;};但是后来我遇到了msvc编译器的问题:(4):errorC2560:'int&Test::f(void)&':cannotoverloadamemberfunctionwithref-qu

由于无法解析重载函数,C++ 绑定(bind)失败

这个问题在这里已经有了答案:std::bindoverloadresolution(3个答案)关闭3年前。voidprintVector(vector&data){for(autoi:data){coutdata{0,1,2,3,4,5,6,7,8,9};vectorresult;result.resize(data.size());transform(data.begin(),data.end(),result,bind(std::pow,_1,2));return0;}抛出的错误是:stlalgo.cpp:22:61:error:nomatchingfunctionforcallt

c++ - tr1::mem_fn 和 tr1::bind:常量正确性和重载

以下代码片段有什么问题?#include#include#includeusingnamespacestd::tr1::placeholders;structabc{typedefvoidresult_type;voidhello(int){std::cout尝试用g++-4.3编译它,似乎cv-qualifier重载函数混淆了tr1::mem_fn和tr1::bind并出现以下错误:nomatchingfunctionforcallto‘bind(,...下面的代码片段编译但似乎破坏了const-correctness:structabc{typedefvoidresult_type

大量使用运算符重载的 C++ XML 库

前段时间我看到一个用于C++的XML库,它大量使用运算符重载,允许可爱类似于以下的语法:#include#includeusingnamespacesome_xml_library;intmain(){elem_tdiv;doc_td=_"hello"_;std::cout输出:helloIIRC库还完全支持属性和嵌套元素。我梦到过这个吗,或者有人知道这个图书馆叫什么吗? 最佳答案 也许this? 关于大量使用运算符重载的C++XML库,我们在StackOverflow上找到一个类似的问

c++ - 摆脱重载的提取运算符? (C++)

我正在尝试使用重载的“>>”来扫描文件中的输入。问题是,我不知道如何处理文件结尾。在这种情况下,我的文件由一个数字组成,后跟几个字符例如:9rl8天6ffistream&operator>>(istream&is,Move&move){charc;inti=0;c=is.get();if(!isalnum(c))return;move.setNum(c);//Iconvertthechartoanint,butI'ledititoutwhile((c=is.get())!='\n'){move.setDirection(i,c);//setscharactercintoinarraya

c++ - friend ,模板,重载<<

我正在尝试使用友元函数重载Point.cpp:11:error:shadowstemplateparm'classT'Point.cpp:12:error:declarationof'constPoint&T'对于这个文件#include"Point.h"templatePoint::Point():xCoordinate(0),yCoordinate(0){}templatePoint::Point(TxCoordinate,TyCoordinate):xCoordinate(xCoordinate),yCoordinate(yCoordinate){}templatestd::os

C++ 隐式转换和重载函数调用中的歧义

我面临以下问题:我有一个类V(比如一个vector),我可以从中生成两个类:CI和I(想想const_iterator和迭代器)。如果我有一个constV,那么我只能生成CI(再次想到iterator和const_iterator)。本质上,我想用(CIci)替换(constV&v),用(Ii)替换(V&v)。此外,我仍然希望能够将Vobj直接传递给需要I或CI的函数,从而实现从V和constV到CI和I的隐式转换。我面临的问题是,虽然重载函数可以区分(constV&v)和(V&v),但当我传递Vobj时,它们无法“区分”(CIci)和(Ii)。在代码中:structV{};struc